/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package privileges.business;

import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Javier
 */
public class UserDataModel extends ListDataModel<User> implements SelectableDataModel<User>{
    public UserDataModel() {  
    }  
  
    public UserDataModel(List<User> data) {  
        super(data);  
    }  
      
    @Override  
    public User getRowData(String rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
          
        List<User> users = (List<User>) getWrappedData();  
          
        for(User user : users) { 
            System.out.println("user host " +user.getHost());
            if(user.getCompositeKey().equals(rowKey))  
                return user;  
        }  
          
        return null;  
    }  
  

    @Override
    public Object getRowKey(User user) {
        return user.getCompositeKey();
    }
}
